﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Jobping.ShortUrls.Models
{
	public class LongUrlValidator
	{
		public string[] ValidDomains { get; set; }

		internal string Validate(string longUrl)
		{
			try
			{
				Uri uri = new Uri(longUrl);

				if (ValidDomains == null)
					return null;

				foreach (var d in ValidDomains)
				{
					if (String.Compare(d.Trim(), uri.Host, true) == 0)
						return null;
				}

				return "Sorry, we don't shorten urls for this domain";
			}
			catch (FormatException ex)
			{
				return "The url entered is not valid. " + ex.Message;
			}
		}
	}
}